package com.yc.study.util;

import org.apache.commons.lang3.time.FastDateFormat;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author 75073
 */
public class DateUtils {
  public static final FastDateFormat FORMAT_yyyyMMdd = FastDateFormat.getInstance("yyyy-MM-dd");

  public static List<Date> generateDates(Date now, int days) {
    ArrayList<Date> dateArrayList = new ArrayList<>();
    for (int i = 0; i < days; i++) {
      Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, days - i);
      try {
        date = FORMAT_yyyyMMdd.parse(FORMAT_yyyyMMdd.format(date));
      } catch (ParseException e) {
        e.printStackTrace();
      }
      dateArrayList.add(date);
    }
    return dateArrayList;
  }
}
